package pa4;

import java.rmi.RemoteException;
import java.util.Random;

import pa4.impl.PeerImpl;
import pa4.impl.SystemManagerImpl;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			SystemManagerImpl<Integer> systemManager = new SystemManagerImpl<Integer>();
			new Thread(systemManager).start();
			Thread.sleep(5000);
			
			new Thread(new PeerImpl<Integer>("A")).start();
			new Thread(new PeerImpl<Integer>("B")).start();
			new Thread(new PeerImpl<Integer>("C")).start();
			new Thread(new PeerImpl<Integer>("D")).start();
			
			Thread.sleep(3000);
			
			//systemManager.getRoot().put(500, "Hallo");
			
			Random r = new Random();
			for(int i = 0; i < 100000; i++){
				Integer key = r.nextInt(Integer.MAX_VALUE);
				int value = key.hashCode();
				systemManager.put(key, value);
				if(i % 10000 == 0){
					System.out.println(systemManager.get(key));
				}
			}
			
			systemManager.printStatistics();
			
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
